<?php

global $_GPC;
global $_W;
$shopid = check_right(2);
if (!$shopid) {
    message('请先选择需要管理的店铺', $this->createWebUrl('shop'), 'error');
}
$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
$cfg = $this->module['config'];
if (!($operation == 'display' || $operation == 'charge')) {
    if ($operation == 'getinfo') {
        $condition = ' and groupid =\'' . $shopid . '\' ';
        intval($_GPC['datetype']);
        switch (intval($_GPC['datetype'])) {
            case 1:
                break;
            case 2:
                break;
            case 3:
                break;
            case 4:
                break;
        }
        if (isset($_GPC['paytype'])) {
            $condition .= ' and paytype = \'' . $_GPC['paytype'] . '\' ';
        }
        if ($_GPC['memberno']) {
            $condition .= ' and memberno>0 ';
        }
        $notmember = pdo_fetch('SELECT count(*) as num1,sum(paid_fee) as num2,sum(num) as num3 FROM ' . tablename('j_hmoney_order') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . ' and memberno=0 ');
        $member = pdo_fetch('SELECT count(*) as num1,sum(paid_fee) as num2,sum(num) as num3 FROM ' . tablename('j_hmoney_order') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . ' and memberno>0 ');
        exit(json_encode(array('success' => true, 'notmember' => $notmember, 'member' => $member)));
    } else {
        if ($operation == 'detail') {
            $userlist = pdo_fetchall('SELECT id,realname FROM ' . tablename('j_hmoney_user') . ' WHERE weid = \'' . $_W['uniacid'] . '\' and pcate=\'' . $shopid . '\' order by id desc');
            $userary = array();
            foreach ($userlist as $row) {
                $userary[$row['id']] = $row['realname'];
            }
            $pindex = max(1, intval($_GPC['page']));
            $psize = 10;
            $condition = ' and a.groupid =\'' . $shopid . '\' ';
            $datetype = $_GPC['datetype'] ? $_GPC['datetype'] : 1;
            switch ($datetype) {
                case 1:
                    $starttime = date('Y-m-d');
                    $endtime = date('Y-m-d');
                    break;
                case 2:
                    $starttime = date('Y-m-d', strtotime('-1 day'));
                    $endtime = date('Y-m-d', strtotime('-1 day'));
                    break;
                case 3:
                    $starttime = date('Y-m-d', strtotime('-6 day'));
                    $endtime = date('Y-m-d');
                    break;
                case 4:
                    $starttime = $_GPC['statrtime'];
                    $endtime = $_GPC['endtime'];
                    break;
            }
            $condition .= ' and a.createdate>=\'' . $starttime . '\' and a.createdate<=\'' . $endtime . '\'  ';
            if ($_GPC['keyword']) {
                $condition .= ' and ( b.cardno like \'%' . $_GPC['keyword'] . '%\' or b.wxcardno like \'%' . $_GPC['keyword'] . '%\' or b.mobile like \'%' . $_GPC['keyword'] . '%\' or b.realname like \'%' . $_GPC['keyword'] . '%\') ';
            }
            if ($_GPC['usetype']) {
                $condition .= ' and a.usetype=\'' . ($_GPC['usetype'] - 1) . '\' ';
            }
            if ($_GPC['mstatus']) {
                $condition .= ' and a.status=\'' . ($_GPC['mstatus'] - 1) . '\' ';
            }
            $condition .= ' and a.cid>0 ';
            $list = pdo_fetchall('SELECT a.*,b.cardno,b.realname,b.wxcardno,b.mobile FROM ' . tablename('j_hmoney_recharge') . ' a left join ' . tablename('j_hmoney_membercard') . ' b on a.cid=b.id WHERE a.weid=\'' . $_W['uniacid'] . '\' ' . $condition . ' order by a.id desc  LIMIT ' . ($pindex - 1) * $psize . ',' . $psize);
            $condition = str_replace('a.', '', $condition);
            $total = pdo_fetchcolumn('SELECT COUNT(*) FROM ' . tablename('j_hmoney_recharge') . ' WHERE weid=\'' . $_W['uniacid'] . '\' ' . $condition . ' ');
            $pager = pagination($total, $pindex, $psize);
        }
    }
}
include $this->template('web/' . $cfg['floder'] . '/salemember');